<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>权限管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="./layui/css/layui.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style type="text/css">
        @media screen and (max-width: 768px) {
            body{
                height: 30rem!important;
            }
            .layui-table-view{
                height:100%!important;
            }
            .layui-table-body{
                height:100%!important;
            }
            .layui-table-tool{
                padding: 0.6rem 0.4rem;
            }
            .layui-table-tool-temp .layui-btn{
                height: 2rem;
                line-height: 2rem;
                padding: 0 0.3rem;
                font-size: 0.6rem;
            }
            .layui-table-view .layui-table{
                width: 100%!important;
            }
            .laytable-cell-1-0-0 {
                width: 1.6rem!important;
                padding: 6px 0;
                margin-left: 18%;
                text-align: center;
            }
            .laytable-cell-1-0-1 {
                font-size: 0.7rem;
                padding: 0.3rem 0;
                width: 1.7rem!important;
                text-align: center;
            }
            .laytable-cell-1-0-2 {
                width: 6rem!important;
                font-size: 0.6rem;
                padding: 0.4rem 0;
                text-align: left;
            }
            .laytable-cell-1-0-3 {
                width: 3rem!important;
                font-size: 0.6rem;
                padding: 0.4rem 0;
                text-align: left;
            }
            .layui-btn-xs {
                padding: 0 0.1rem;
                font-size: 0.5rem;
            }
            .layui-table-view .layui-form-checkbox[lay-skin=primary] i {
                width: 0.9rem;
                height: 0.9rem;
            }
            .layui-table-column{
                padding: 0.5rem 0.2rem;
            }
            .layui-table-page .layui-laypage a{
                padding: 0 0.4rem;
                font-size: 0.6rem;
            }
            .layui-table-page .layui-laypage span{
                font-size: 0.6rem;
            }
            .layui-table-page .layui-laypage input{
                width: 1.8rem!important;
                padding: 0.1rem;
            }
            .layui-table-page{
                overflow: scroll;
            }
            .layui-table-view .layui-table td,.layui-table-view .layui-table th{
                padding: 0 2%!important;
            }
            .layui-table-fixed-l{
                width: 15%;
            }
            .layui-table-tool-self{
                right: 0.4rem!important;
            }
            .layui-icon{
                font-size: 0.9rem;
            }
            .layui-table-tool .layui-inline[lay-event] {
                width: 1rem;
                height: 1rem;
                padding: 0;
            }
            .layui-layer-title{
                font-size: 0.9rem!important;
            }
            .layui-elem-field legend {
                font-size: 1rem!important;
            }


        /* 权限管理弹出页*/
            .layui-layer-title{
                font-size: 0.7rem!important;
                overflow: visible!important;
            }
            .layui-layer-iframe{
                width: 90%!important;
                height: 97%!important;
                top: 7px!important;
                left: 7px!important;
            }
            /*    建立职位*/
            #builddiv{
                width: 100%!important;
                height: 200px!important;
            }
            #builddiv .layui-form-item{
                padding-top: 10px;
                font-size:0.75rem!important;
            }
            #builddiv .layui-form-item .layui-form-label {
                width: 20%;
                height: 25px;
                line-height: 10px;
                text-align: left;
                padding: 8px 1px 8px 3px !important;
                min-width: 45px;
            }
            #builddiv .layui-form-item .layui-input-block input{
                height: 25px;
                line-height: 10px;
            }
            #builddiv .layui-form-item .layui-input-block {
                margin-left: 45px;
                width: 65%;
            }
            #builddiv .layui-form-item .layui-input-block button{
                font-size: 0.7rem !important;
                height: 25px;
                line-height: 25px;
                padding: 0 4px;
            }
        }
    </style>
</head>

<body>
<script src="./layui/layui.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="roledeal">权限管理</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></script>
<script type="text/html" id="toolbarDemo" >
    <button class="layui-btn" lay-event="build">建立职位</button>
</script>

<table class="layui-hide" id="positiontable" lay-filter="positiontable"></table>
<div style="display: none;width: 800px;height: 600px" id="builddiv" >
    <form class="layui-form layui-form-pane" action="/position/add">
        <input  name="idedit" style="display: none" >
        <div class="layui-form-item">
            <label class="layui-form-label">职位名</label>
            <div class="layui-input-block">
                <input type="text" name="positionName"   class="layui-input" lay-verify="positionName|required">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="createPosition">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script th:inline=none>
    layui.use(['table', 'dropdown'], function(){
        var table = layui.table;
        var dropdown = layui.dropdown;
        var $ = layui.$;
        var form=layui.form
        layui.form.on('submit(createPosition)', function(data){
            //demo1表单提交（开户）
            $.post("/position/add",{
                "positionName" : data.field.positionName
            }, function(data) {
                if(data.code==20000){
                    layer.msg(data.msg)
                    table.reload('positiontable');
                }
                else {
                    $('input[name="positionName"]').val('');
                    layer.closeAll()
                    layer.msg("新建成功")
                    table.reload('positiontable');
                    form.render();
                }

            });
            return false;
        });
        // 创建渲染实例
        table.render({
            elem: '#positiontable'
            ,url:'/position/queryposition',
            height: 'full-0'
            , limit:20,
            limits:[20],
            response: {
                statusCode: 10000 //规定成功的状态码，默认：0
            }
             , toolbar: '#toolbarDemo'
            ,height: 'full-200' // 最大高度减去其他容器已占有的高度差
            ,cellMinWidth: 80
            ,page: true
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'positionId',  title: 'id'}
                ,{field:'positionName',  title: '权限名称'}
                ,{title:'操作',  toolbar: '#barDemo'}
            ]],
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
            ,error: function(res, msg){
                console.log(res, msg)
            }
        });
        table.on('tool(positiontable)', function(obj){
            var data = obj.data;
            if(obj.event === 'roledeal'){
                layer.open({
                    type: 2,
                    title: '权限管理',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['90%', '90%'],
                    content: '/position/queryrolepage?positionId='+data.positionId
                });
            } else if(obj.event === 'del'){
                layer.confirm('删除选项', {
                    btn: ['确认删除', '还是算了'] //按钮
                }, function () {
                    $.ajax({
                            url: '/position/deleteOnePosition?positionId=' + data.positionId,
                            dataType: 'json',
                            type: 'post',
                            success: function (data) {
                                layer.closeAll();
                                table.reload('positiontable');
                            }, error: function () {
                                alert("删除失败")
                                layer.closeAll();
                            }
                        }
                    )
                }, function () {
                    layer.closeAll();
                });

            }

        })
        table.on('toolbar(positiontable)', function(obj){
            switch(obj.event){
                case 'build':
                    layer.open({
                        title: '建立职位',
                        type: 1,
                        shadeClose: true,
                        content:layui.$('#builddiv')
                    });

            }
        });
    });
</script>
</body>
</html>